enum DIRLIST {
    //% block="北风"
    0,
    //% block="东北风"
    1
    //% block="东风"
    2,
    //% block="东南风"
    3
    //% block="南风"
    4,
    //% block="西南风"
    5    
    //% block="西风"
    6,
    //% block="西北风"
    7
}


//% color="#5ba55b" iconWidth=50 iconHeight=40
namespace RS485_FSFX { 

    //% block="风速风向传感器 接收(R)管脚#[RXPIN] 发射(T)管脚#[TXPIN] 初始化" blockType="command"
    //% RXPIN.shadow="dropdown" RXPIN.options="PIN_DigitalWrite" 
    //% TXPIN.shadow="dropdown" TXPIN.options="PIN_DigitalWrite"
    export function RS485_FSFX_INIT(parameter: any, block: any) {
        let rxpin = parameter.RXPIN.code;
        let txpin = parameter.TXPIN.code;
        Generator.addInclude('include_RL_RS485_FSFX_h', '#include "RL_RS485_FSFX.h"');
        Generator.addObject(`RS485_FSFX_rs485_fsfx`, `RS485_FSFX`,  `rs485_fsfx(${rxpin},${txpin});`);
        Generator.addSetup(`rs485_fsfx_begin`, `rs485_fsfx.begin(4800);`);
       // Generator.addCode(`rs485_fsfx${rxpin}${txpin}.readfs()`);
    }   
    //% block="风速传感器 请求数据" blockType="command"
    export function RS485_FSFX_REQUESTFS(parameter: any, block: any) {
       Generator.addCode(`rs485_fsfx.requestfs();`);
    }  
    //% block="风速传感器 检测到风速值(m/s)" blockType="reporter"
    export function RS485_FSFX_READFS(parameter: any, block: any) {
        Generator.addCode(`rs485_fsfx.readfs()`);
    }   
    //% block="风速传感器 检测到风速等级" blockType="reporter"
    export function RS485_FSFX_READFS_LEVEL(parameter: any, block: any) {
        Generator.addCode(`rs485_fsfx.readfs_level()`);
    } 
    //% block="风向传感器 请求数据" blockType="command"
    export function RS485_FSFX_REQUESTFX(parameter: any, block: any) {
       Generator.addCode(`rs485_fsfx.requestfx();`);
    }
    //% block="风向传感器 检测到风向(°)" blockType="reporter"
    export function RS485_FSFX_READFX(parameter: any, block: any) {
        Generator.addCode(`rs485_fsfx.readfx()`);
    }  
    //% block="风向传感器 检测到风向为[DIR]" blockType="boolean"
    //% DIR.shadow="dropdown" DIR.options="DIRLIST"
    export function RS485_FSFX_READFX_DIR(parameter: any, block: any) {
        let dir = parameter.DIR.code;
        Generator.addCode(`rs485_fsfx.readfx_dir(${dir})`);
    }
   
}
